package minidb.parse.exps;
import java.util.*;
import minidb.parse.exps.*;

public class TransactionExp extends SQLExp
{
	public SqlExpList tr_exps;
	
	public TransactionExp(SqlExpList el)
	{
		this.tr_exps=el;
	}
	
	public Set<String> RetrieveLockTables()
	{
		Set<String> tns=new HashSet<String>();
		for(SQLExp exp:this.tr_exps.GetSqlExpList())
		{
			if(InsertExp.class.isInstance(exp))
				tns.add(((InsertExp)exp).tableName);
			else if(UpdateExp.class.isInstance(exp))
				tns.add(((UpdateExp)exp).tableName);
			else if(DeleteExp.class.isInstance(exp))
				tns.add(((DeleteExp)exp).tableName);
			else
				throw new RuntimeException("TransactionExp.RetrieveLockTables():unexpected transaction expression type");
		}
		return tns;
	}
	
	@Override
	public String Print()
	{
		return "START TRANSACTION\n"+this.tr_exps.Print()+"COMMIT\n";
	}

}
